import {get,postByJson} from '../static/common/util/http'
import {nuxtBaseUrl} from '../config/index'
import {getUserFromLocalStorage} from '../static/lib/wxauth'

class Services {

  async getSeller(id) {
    console.log('进入services.getSeller')
    console.log(`nuxtBaseUrl:${nuxtBaseUrl}`)
    // const res = await get(`${nuxtBaseUrl}/getseller/${id}`)
    const res = await get(`${nuxtBaseUrl}/getseller?id=${id}`)
    return res.data;
  }

  async getProducts(id) {
    console.log('进入services.getProducts')
    // const res = await get(`${nuxtBaseUrl}/getproductions/${id}`)
    const res = await get(`${nuxtBaseUrl}/getproductions?id=${id}`)
    return res.data;
  }

  async getRatings(id) {
    console.log('进入services.getRatings')
    // const res = await get(`${nuxtBaseUrl}/getratings/${id}`)
    const res = await get(`${nuxtBaseUrl}/getratings?id=${id}`)
    return res.data
  }
  
  // 从localStorage中获取user
  async getUser(id) {
    console.log('进入services.getUser')
    const res = getUserFromLocalStorage(id)
    return res
  }
  
  async createOrder(newOrder) {
    console.log('进入services.createorder')
    const res = await postByJson(`${nuxtBaseUrl}/createorder`, newOrder)
    return res.data;
  }

}

export default new Services()